﻿using System;
using System.Threading;
using System.Threading.Tasks;

namespace ZilLion.Service.Core.Infrastructure.Filters
{
    public class WebapiTraceAtrribute : ActionFilterAttribute
    {
        //public override void OnActionExecuting(HttpActionContext actionContext)
        //{
        //    ZilLionLogManager.GetLogger(ProjectType.WebApi).Trace("请求上下文",actionContext);
        //    base.OnActionExecuting(actionContext);
        //}
        public override Task OnActionExecutedAsync(HttpActionExecutedContext actionExecutedContext,
            CancellationToken cancellationToken)
        {
            return Task.Run(() =>
            {
                try
                {
                    ZilLionLogManager.Instance()
                        .Trace(actionExecutedContext.ActionContext.Request.RequestUri.ToString(),
                            actionExecutedContext.ActionContext);
                }
                catch (Exception)
                {
                    // ignored
                }
            }, cancellationToken);
        }
    }
}